package org.ediba.siri.core.model.data;

import java.util.Collection;
import java.util.Map;

import org.ediba.siri.core.Filter;
import org.ediba.siri.core.common.data.HibernateDomainDao;
import org.ediba.siri.core.model.domain.ModelSchool;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

public class HibernateModelSchoolDao extends HibernateDomainDao<ModelSchool, Integer> implements ModelSchoolDao{

	public HibernateModelSchoolDao() {super(ModelSchool.class);}

	@Override
	protected DetachedCriteria buildCriteria(Map<Filter, Collection<Object>> filters) {
		DetachedCriteria detachedCriteria = this.buildCriteria();
		for (Map.Entry<Filter,Collection<Object>> filter : filters.entrySet()){
			for (Object value : filter.getValue())
				switch (filter.getKey()) {
				case NAME: 		detachedCriteria.add(Restrictions.ilike(Filter.NAME.getProperty(), (String)value, MatchMode.START));
				break;
				}
		}
		return detachedCriteria;
	}
}
